package com.welove.app;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.welove.http.TBaseHttpClient;
import com.welove.util.EtIbUtil;
import com.welove.util.InternetUtil;
import com.welove.util.PreferenceUtil;
import com.welove.util.StringUtil;
import android.app.Application;
import android.util.Log;


public class TBaseApplication extends Application {
	
	private static StringUtil stringUtil;
	private static InternetUtil internetUtil;
	private static TBaseHttpClient httpClient;
	private static PreferenceUtil preferenceUtil;
	private static EtIbUtil etIbUtil;
	
	
	
	//百度定位相关
	public LocationClient mLocationClient = null;
	public MyLocationListenner myListener = new MyLocationListenner();
	
	//定位结果
	public String city;
	public String province;
	public String district;
	public String street;
	
	public void onCreate() {
		// TODO Auto-generated method stub
		
		
		this.internetUtil=new InternetUtil(this);
		this.stringUtil=new StringUtil();
		this.preferenceUtil=new PreferenceUtil(this);
		this.etIbUtil=new EtIbUtil();
		
		
		httpClient=new TBaseHttpClient();
		mLocationClient = new LocationClient( this );

		mLocationClient.registerLocationListener( myListener );
		super.onCreate();
		
	}
	
	public static StringUtil getStringUtil()
	{
		return stringUtil;
	}
	
	public static TBaseHttpClient getHttpClient()
	{
		return httpClient;
	}
	
	
	public static PreferenceUtil getPreferenceUtil()
	{
		return preferenceUtil;
	}
	
	
	public static InternetUtil getInternetUtil()
	{
		return internetUtil;
	}
	
	public static EtIbUtil getEtIbUtil() {
		return etIbUtil;
	}
	
	public class MyLocationListenner implements BDLocationListener {
		@Override
		public void onReceiveLocation(BDLocation location) {
			
			
			if (location == null)
				return ;
			
			
			if (location.getLocType() == BDLocation.TypeNetWorkLocation){

				city=location.getCity();
				province=location.getProvince();
				district=location.getDistrict();
				street=location.getStreet();
				
			}
			
		
		}
		
		public void onReceivePoi(BDLocation poiLocation) {
			
		}
	}

	@Override
	public void onTerminate() {
		// TODO Auto-generated method stub
		super.onTerminate();
	}
	
	
	
	
}
